﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SmartRoute.BingMaps.ImageryService;
using SmartRoute.Data;
using System.ComponentModel;


namespace SmartRoute.BingMaps
{
    public class ImageryGroup: INotifyPropertyChanged
    {
        //public struct TogglableGraphic
        //{
        //    Action Notify;
        //    bool _checkmark;
        //    public bool Toggled
        //    {
        //        get {return _checkmark;}
        //        set { _checkmark = value; Notify(); }
        //    }
        //    public TogglableGraphic(Action notifier)
        //    {
        //        Notify = notifier;
        //    }
        //}
        List<Imagery> currentImagingModules;

        Imagery currentModule;

        string currentRouteDirections;

        public string CurrentRouteDirections
        {
            get { return currentRouteDirections; }
            //set { currentRouteDirections = value; }
        }

        public Imagery CurrentModule
        {
            get { return currentModule; }
            //set { currentModule = value; }
        }
        GeometryGroup currentLines;

        //contains the current set of lines
        public GeometryGroup CurrentLines
        {
            get { return currentLines; }
            //set { currentLines = value; }
        }

        bool[] currentVisible;

        public bool[] CurrentVisible
        {
            get { return currentVisible; }
            set { currentVisible = value; Notify("CurrentVisible"); }
        }

        //contains the current image
        ImageSource mapImage;

        public ImageSource MapImage2
        {
            get { return mapImage; }
            set { mapImage = value; }
        }

        List<Route> currentRoutes;

        /*
        public string CurrentRoutes
        {
            get {   List<string> printout = new List<string>();
                    foreach(Route route in currentRoutes)
                    {
                        string rep = route.Directions;
                        printout.Add(rep);

                    }
                    return printout[0];
                }
            set { }
        }
         */

        

        public ImageryGroup()
        {
            
            this.currentImagingModules = new List<Imagery>();
            currentModule = null;
            currentLines = null;
            currentVisible = null;
            mapImage = null;
            currentRoutes = null;
        }

        public void addImageryModule(Imagery module)
        {
            this.currentImagingModules.Add(module);
        }

        public void setCurrent(int index)
        {
            currentModule = currentImagingModules[index];
            currentLines = currentModule.DrawnRoutesGrouping;
            currentRoutes = currentModule.Routes;
            currentVisible = new bool[currentModule.DrawnRoutesGrouping.Children.Count];
            for (int i = 0; i < currentVisible.Count(); i++)
            {
                currentVisible[i] = true;
            }
            currentRouteDirections = currentModule.Routes[0].Directions;
            mapImage = currentModule.MapImage;
            Notify("MapImage2");
            Notify("CurrentLines");
            Notify("CurrentRoutes");
            Notify("CurrentRouteDirections");
            Notify("CurrentVisible");
        }

        public void changeCurrentRouteDirectionsDisplayed(int routeNumber)
        {
            if (routeNumber < this.currentRoutes.Count)
            {
                this.currentRouteDirections = currentModule.Routes[routeNumber].Directions;
                Notify("CurrentRouteDirections");
            }
        }

        public void changeCurrentRouteDisplayedMap(bool displays, int routeNum)
        {
            if (currentVisible[routeNum] == displays) { }
            else
            {
                this.CurrentModule.setVisible(displays, routeNum);
                currentVisible[routeNum] = displays;
                Notify("CurrentVisible");
            }

        }

        public void bindingTest()
        {
            
            Notify("MapImage2");
            Notify("CurrentLines");
            
            Notify("CurrentRoutes");
            Notify("CurrentRouteDirections");
            Notify("CurrentVisible");
             
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void Notify(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion


    }
}
